/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.flf.audioteca.entidades;

import br.edu.flf.audioteca.enums.CategoriaDoAlbum;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Nathan Azevedo
 */
@Entity
@Table(name = "tb_album")
@NamedQueries({
    @NamedQuery(name = "Album.findAll", query = "SELECT a FROM Album a"),
    @NamedQuery(name = "Album.findByIdCd", query = "SELECT a FROM Album a WHERE a.codigoDoAlbum = :codigoDoAlbum"),
    @NamedQuery(name = "Album.findByIdCategoriaFk", query = "SELECT a FROM Album a WHERE a.codigoDaCategoria = :codigoDaCategoria"),
    @NamedQuery(name = "Album.findByIdArtistaFk", query = "SELECT a FROM Album a WHERE a.artistaDono.codigoArtista = :codigoArtista"),
    @NamedQuery(name = "Album.findByNmTitulo", query = "SELECT a FROM Album a WHERE a.nomeDoAlbum = :nomeDoAlbum"),
    @NamedQuery(name = "Album.findByNuCds", query = "SELECT a FROM Album a WHERE a.numeroDeCDs = :numeroDeCDs")})
public class Album implements Serializable {

    private static final long serialVersionUID = 1L;
    //
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "id_cd")
    private Integer codigoDoAlbum;
    //
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "id_categoria_fk", nullable = false)
    private CategoriaDoAlbum codigoDaCategoria;
    //
    @ManyToOne(optional = false, fetch = FetchType.LAZY,
    cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    @JoinColumn(referencedColumnName = "id_artista", name = "id_artista_dono")
    private Artista artistaDono;

    //
    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE},
    fetch = FetchType.LAZY, mappedBy = "albumDaMusica")
    private Collection<Musica> musicasDoAlbum;
    //
    @Column(name = "nm_titulo")
    private String nomeDoAlbum;
    //
    @Column(name = "nu_cds")
    private Integer numeroDeCDs;

    public Integer getCodigoDoAlbum() {
        return codigoDoAlbum;
    }

    public void setCodigoDoAlbum(Integer codigoDoAlbum) {
        this.codigoDoAlbum = codigoDoAlbum;
    }

    public Artista getArtistaDono() {
        return artistaDono;
    }

    public void setArtistaDono(Artista artistaDono) {
        this.artistaDono = artistaDono;
    }

    public CategoriaDoAlbum getCodigoDaCategoria() {
        return codigoDaCategoria;
    }

    public void setCodigoDaCategoria(CategoriaDoAlbum codigoDaCategoria) {
        this.codigoDaCategoria = codigoDaCategoria;
    }

    public String getNomeDoAlbum() {
        return nomeDoAlbum;
    }

    public void setNomeDoAlbum(String nomeDoAlbum) {
        this.nomeDoAlbum = nomeDoAlbum;
    }

    public Integer getNumeroDeCDs() {
        return numeroDeCDs;
    }

    public void setNumeroDeCDs(Integer numeroDeCDs) {
        this.numeroDeCDs = numeroDeCDs;
    }

    public Collection<Musica> getMusicasDoAlbum() {
        return musicasDoAlbum;
    }

    public void setMusicasDoAlbum(Collection<Musica> musicasDoAlbum) {
        this.musicasDoAlbum = musicasDoAlbum;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Album other = (Album) obj;
        if (this.codigoDoAlbum != other.codigoDoAlbum && (this.codigoDoAlbum == null || !this.codigoDoAlbum.equals(other.codigoDoAlbum))) {
            return false;
        }
        if (this.codigoDaCategoria != other.codigoDaCategoria) {
            return false;
        }
        if (this.artistaDono != other.artistaDono && (this.artistaDono == null || !this.artistaDono.equals(other.artistaDono))) {
            return false;
        }
        if ((this.nomeDoAlbum == null) ? (other.nomeDoAlbum != null) : !this.nomeDoAlbum.equals(other.nomeDoAlbum)) {
            return false;
        }
        if (this.numeroDeCDs != other.numeroDeCDs && (this.numeroDeCDs == null || !this.numeroDeCDs.equals(other.numeroDeCDs))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + (this.codigoDoAlbum != null ? this.codigoDoAlbum.hashCode() : 0);
        hash = 23 * hash + (this.codigoDaCategoria != null ? this.codigoDaCategoria.hashCode() : 0);
        hash = 23 * hash + (this.artistaDono != null ? this.artistaDono.hashCode() : 0);
        hash = 23 * hash + (this.nomeDoAlbum != null ? this.nomeDoAlbum.hashCode() : 0);
        hash = 23 * hash + (this.numeroDeCDs != null ? this.numeroDeCDs.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Album: " + getNomeDoAlbum();
    }
}
